package org.jugile.jsontmpl.domain;

import java.io.Serializable;
import org.jugile.util.*;

public abstract class Entity extends Jugile implements Serializable, IDO, Comparable {
	public final static long serialVersionUID = 4;


	protected void id(long v) { id = v; } 
	private long id;
	public long id() { return id; }
	public String getId() { return ""+id; }

	private boolean isVirgin = false;
	public void setVirgin(boolean v) { isVirgin = v; }
	public boolean isVirgin() { return isVirgin; }
	
	private Long version = new Long(0);
	public Long getVersion() { return version; }
	protected void setVersion(Long v) { version = v; }
	protected void setVersion(int v) { version = (long)v; }
	protected void incrVersion() { version++; }

	public boolean equals(IDO e) {
		if (e == null) return false;
		if (e.getId() == null) return false;
		return getId().equals(e.getId());
	}
	
	public int hashCode() { return (new Long(id)).hashCode(); }
	
	public Domain getDomain() {
		return Domain.getDomain();
	}
	public Domain d() {
		return getDomain();
	}

	public int compareTo(Object o) {
		if (o instanceof IDO) {
			if (o == null) return 1;
			return getId().compareTo(((IDO)o).getId());
		}
		return -1;
	}

	public boolean matches(Object spec) { return false; }
	public String txtIdx(String lang) { return ""; }
	
	protected String _getTableName() { return ""; }
	protected void _writeFlds(DBConnection c) throws Exception { return; }
	public abstract void onDeleteEvent();
	public abstract void onLoad(IDomain d);
}